import getpass
import gdata.service
import gdata.spreadsheet
import gdata.spreadsheet.service
import feedparser

class connect:
           
    def initialize(self):
        self.gd_client.email = self.user
        self.gd_client.password = self.pwd
        self.gd_client.ProgrammaticLogin()
        self.spreadsheet_key = ""
        self.worksheet_key = ""
        
    def spreadsheetfeed(self):
        spreadsheet_feed = self.gd_client.GetSpreadsheetsFeed()
        for spreadsheet in spreadsheet_feed.entry:
            print "Spreadsheet key: %s | Spreadsheet title: %s" % (spreadsheet.id.text.rsplit('/',1)[1],spreadsheet.title.text)
            
    def selectspreadsheet(self,key):
        self.spreadsheet_key = key

    def worksheetfeed(self):
        if (self.spreadsheet_key):
            worksheet_feed = self.gd_client.GetWorksheetsFeed(self.spreadsheet_key)
            for worksheet in worksheet_feed.entry:
                print "Worksheet key: %s | Worksheet title: %s" % (worksheet.id.text.rsplit('/',1)[1],worksheet.title.text)
        else:
            print "why in the world would you expect me to work without Spreadsheet Key"

    def selectworksheet(self,key):
        self.worksheet_key = key

    def read(self):
        list_feed = self.gd_client.GetListFeed(self.spreadsheet_key,self.worksheet_key)
        #for entry in list_feed.entry:
           # print feedparser.parse(str(entry))
          #  print "%s; %s\n" % (entry.title.text, entry.content.text)
       # return feedparser.parse(str(list_feed.entry[0]))
        return list_feed    
    def __init__(self,user,pwd):
        self.user = user
        self.pwd = pwd
        self.gd_client = gdata.spreadsheet.service.SpreadsheetsService()


obj = connect('itrcstaf@isu.edu','th3ho?T!')
obj.initialize()
#obj.spreadsheetfeed()
obj.selectspreadsheet('tyi1CXANV0MCCmeGW2dUHMg')
#obj.worksheetfeed()
obj.selectworksheet('od6')
feed = obj.read()

